<template>
  <div class="center-section-content">
    <div class="box">
      <div
        class="container"
        @click="clickContainer(1)"
        :class="{ active: activeContainer === 1 }"
      >
        <div class="title">科普场馆介绍</div>
        <div class="item" v-for="item in placeList" :key="item.id">
          <div
            class="item-title"
            :class="{ active: activeItemId === item.id }"
            @click="setActiveItem(item.id)"
          >
            <img
              :style="{
                visibility: activeItemId === item.id ? 'visible' : 'hidden',
              }"
              src="@/assets/img/create-arrow.png"
              alt=""
            />
            <span>{{ item.name }}</span>
          </div>
        </div>
      </div>
      <div
        class="container"
        @click="clickContainer(2)"
        :class="{ active: activeContainer === 2 }"
      >
        <div class="title">科普解说系统</div>
        <div class="work-item">
          以<span class="highlight">“微科普”</span
          >形式将科普课堂融入园区游览路线，便于公众对照园内真实动植物了解学习相关知识。
        </div>
      </div>
      <div
        class="container"
        @click="clickContainer(3)"
        :class="{ active: activeContainer === 3 }"
      >
        <div class="title">
          <div>科普教育活动</div>
        </div>
        <video src="@/assets/videos/tv-demo.mp4" controls class="video"></video>
      </div>
    </div>

    <div class="device-tabs">
      <div
        v-for="item in list"
        :key="item.id"
        :class="['device-tab', { active: active === item.id }]"
        @click="handleDeviceClick(item.id, item.data)"
      >
        <span>{{ item.name }}</span>
      </div>
    </div>
  </div>
</template> 

<script>

export default {
  name: "Center",
  inject: ['getSvgMapDom', 'getSvgMapComponent'],
  data() {
    return {
      list: [
        { id: "road", name: "体验之路", data: "" },
        { id: "science-education", name: "科普教育", data: "" }
      ],
      activeContainer: 1,
      activeItemId: '',
      active: "science-education",
      placeList: [
        {
          id: "xinjian01",
          name: "植物楼",
        },
        {
          id: "haipai04",
          name: "黄母祠",
        },
        {
          id: "guonei02",
          name: "上海盆景博物馆",
        },
        {
          id: "xinjian02",
          name: "自然中心",
        },
        {
          id: "wenshi01",
          name: "展览温室",
        },
        {
          id: "haipai02",
          name: "兰室",
        },
      ],
    };
  },
  mounted() {},
  created() {
    this.setActiveItem(this.$route.query.scienceId);
  },
  methods: {
    handleDeviceClick(id, data) {
      this.active = id;
      if (id == "road") {
        this.$router.push("/ExperienceRoad");
      }
    },
    setActiveItem(id) {
      if (id == this.activeItemId) {
        return;
      }
      this.activeItemId = id;
      this.$router.push({
        query: {
          scienceId: id,
        },
      });
      
      // 使用 provide/inject 方式获取 SvgMap 组件
      this.$nextTick(() => {
        const svgMapComponent = this.getSvgMapComponent();
        if (svgMapComponent && typeof svgMapComponent.setAllPathsColor === 'function') {
          svgMapComponent.setAllPathsColor();
          svgMapComponent.highlightArea(id);
        } else {
          console.warn('SvgMap 组件未正确加载或方法不存在');
        }
      });
    },
    clickContainer(item) {
      if (item == this.activeContainer) {
        return;
      }
      this.activeContainer = item;
    },
  },
};
</script>

<style lang="scss" scoped>
.device-tabs {
  display: flex;
  gap: 10px;
  padding: 10px 0;
  justify-content: center;
}

.device-tab {
  width: 197px;
  height: 60px;
  pointer-events: auto;
  color: #ccc;
  cursor: pointer;
  font-size: 14px;
  text-align: center;
  background: url("@/assets/img/species-center-tab-normal-bg.png") no-repeat
    center;
  background-size: 100% 100%;
  transition: all 0.3s ease;
  user-select: none;

  &.active {
    background-image: url("@/assets/img/species-center-tab-active-bg.png");
    color: #fff;
  }

  &:hover {
    color: #fff;
  }
  span {
    font-size: 18px;
    display: inline-block;
    margin-top: 24px;
  }
  div {
    font-size: 12px;
  }
}
.box {
  display: flex;
  flex-direction: row;
  gap: 8px;
  bottom: 84px;
  height: 180px;
  width: 100%;
  pointer-events: auto;
  .container {
    flex: 1;
    pointer-events: auto;
    padding: 7px 7px 0 7px;
    background-image: url("@/assets/img/center-tab-bg.png");
    background-size: 100% 100%;
    background-repeat: no-repeat;
    &.active {
      background-image: url("@/assets/img/center-tab-active-bg.png");
    }
    .title {
      background: linear-gradient(
        to right,
        rgba(22, 60, 135, 1),
        rgba(14, 37, 81, 0.7),
        rgba(7, 15, 28, 0)
      );
      font-size: 14px;
      color: #fff;
      height: 27px;
      line-height: 27px;
      padding: 0 10px;
    }
    .item {
      padding: 5px 5px 0 5px;
      font-size: 12px;
      .item-title {
        color: #fff;
        cursor: pointer;
        display: flex;
        align-items: center;
        img {
          display: inline-block;
          margin-right: 6px;
          width: 12px;
          height: 12px;
        }
        &.active {
          color: #07ffe5;
          img {
            display: inline-block;
          }
        }
      }
    }
    .work-item {
      font-size: 12px;
      color: #fff;
      padding: 10px;
      line-height: 30px;
      .highlight {
        color: #07ffe5;
      }
    }
    .video {
      width: 100%;
      height: 80%;
      object-fit: cover;
    }
  }
}
</style>
